package com.jinlejia.erp.ui.home;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baidu.mapapi.search.geocode.GeoCodeOption;
import com.baidu.mapapi.search.geocode.GeoCodeResult;
import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeResult;
import com.jinlejia.erp.R;
import com.jinlejia.erp.adapter.VisitScheduleAdapter;
import com.jinlejia.erp.base.ApiConfig;
import com.jinlejia.erp.base.MapCallBack;
import com.jinlejia.erp.databinding.ActivityVisitScheduleBinding;
import com.jinlejia.erp.ui.common.ProgressDialog;
import com.jinlejia.erp.ui.customer.AddHouseActivity;
import com.jinlejia.erp.ui.house.HouseDetailActivity;
import com.jinlejia.erp.utils.DataFilter;
import com.jinlejia.erp.utils.DateUtil;
import com.jzxiang.pickerview.TimePickerDialog;
import com.jzxiang.pickerview.data.Type;
import com.jzxiang.pickerview.listener.OnDateSetListener;
import com.weight.CustomToast;
import com.zhy.http.okhttp.OkHttpUtils;

import org.simple.eventbus.EventBus;
import org.simple.eventbus.Subscriber;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.MediaType;

/**
 * 安排日程（录约看）
 */

public class VisitScheduleActivity extends AppCompatActivity implements OnDateSetListener {

    private VisitScheduleAdapter adapter;
    private ArrayList<Map<String, Object>> dataList = new ArrayList<>();
    private JSONObject jsonObject = new JSONObject();
    private JSONObject commitObjcet = new JSONObject();
    private String place;
    private String state;
    private String pointx, pointy;
    private int type = 0;
    private String sex;
    private int count;
    private String startTimeStr, endTimeStr;
    private ProgressDialog progressDialog;

    private ActivityVisitScheduleBinding binding;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_visit_schedule);

        binding.backBtn.setOnClickListener(this::onClick);
        binding.startTime.setOnClickListener(this::onClick);
        binding.endTime.setOnClickListener(this::onClick);
        binding.placeToMeet.setOnClickListener(this::onClick);
        binding.deleteIcon.setOnClickListener(this::onClick);
        binding.addVisitHouse.setOnClickListener(this::onClick);
        binding.preview.setOnClickListener(this::onClick);
        binding.save.setOnClickListener(this::onClick);
        EventBus.getDefault().registerSticky(this);
        EventBus.getDefault().register(this);
        initView();
        initEvent();
    }

    private void initEvent() {
        adapter.setCallBack(new VisitScheduleAdapter.onClickCallback() {
            @Override
            public void onClickListener(int position, ArrayList<Map<String, Object>> data) {
                EventBus.getDefault().postSticky(adapter.getData(), "TAG_DATA");
                Intent intent = new Intent(VisitScheduleActivity.this, VisitIntroduceActivity.class);
                intent.putExtra("position", position);
                startActivity(intent);
            }
        });
        adapter.setOnHouseItemClickListener(new VisitScheduleAdapter.OnHouseItemClickListener() {
            @Override
            public void OnHouseItemClick(String code) {
                Intent hIntent = new Intent(VisitScheduleActivity.this, HouseDetailActivity.class);
                hIntent.putExtra("code", code);
                hIntent.putExtra("type", getIntent().getStringExtra("type"));
                startActivity(hIntent);
            }
        });
    }

    /**
     * 初始化视图
     */
    private void initView() {
        progressDialog = new ProgressDialog(this,"请稍后...");
        if (!TextUtils.isEmpty(getIntent().getStringExtra("property"))) {
            state = getIntent().getStringExtra("property");
        }

        if (!TextUtils.isEmpty(getIntent().getStringExtra("sex"))) {
            if (getIntent().getStringExtra("sex").equals("1")) {
                sex = "先生";
            } else {
                sex = "女士";
            }
        }
        if (state.equals("Input")) {//添加
            dataList.clear();
            binding.bottomAddHouse.setVisibility(View.VISIBLE);
            binding.scheduleRecycleView.setVisibility(View.GONE);
            if (!TextUtils.isEmpty(getIntent().getStringExtra("customerName")))
                binding.appointmentName.setText(getIntent().getStringExtra("customerName").concat(" " + sex));
            type = 1;

        } else if (state.equals("Again")) { //修改
            type = 0;
            if (!TextUtils.isEmpty(getIntent().getStringExtra("customerName")))
                binding.appointmentName.setText(getIntent().getStringExtra("customerName").concat(" " + sex));
            if (!TextUtils.isEmpty(getIntent().getStringExtra("firsttime")))
                binding.firstTimeText.setText(DateUtil.getTime(getIntent().getStringExtra("firsttime"), "yyyy-MM-dd HH:mm"));
                startTimeStr = DateUtil.getTime(getIntent().getStringExtra("firsttime"), "yyyy-MM-dd HH");
            if (!TextUtils.isEmpty(getIntent().getStringExtra("lasttime")))
                binding.lastTimeText.setText(DateUtil.getTime(getIntent().getStringExtra("lasttime"), "yyyy-MM-dd HH:mm"));
            endTimeStr = DateUtil.getTime(getIntent().getStringExtra("lasttime"), "yyyy-MM-dd HH");
            if (!TextUtils.isEmpty(getIntent().getStringExtra("place")))
                place = getIntent().getStringExtra("place");
            if (!TextUtils.isEmpty(getIntent().getStringExtra("pointx")))
                pointx = getIntent().getStringExtra("pointx");
            if (!TextUtils.isEmpty(getIntent().getStringExtra("pointy")))
                pointy = getIntent().getStringExtra("pointy");
            binding.houseCount.setText("约看房源（" + getIntent().getIntExtra("number", 0) + "）");
            binding.addressMeet.setText(place);
        }

        if (getIntent().getIntExtra("number", 0) > 0) {
            binding.bottomAddHouse.setVisibility(View.GONE);
            binding.scheduleRecycleView.setVisibility(View.VISIBLE);
        } else {
            binding.bottomAddHouse.setVisibility(View.VISIBLE);
            binding.scheduleRecycleView.setVisibility(View.GONE);
        }


        binding.scheduleRecycleView.setHasFixedSize(true);
        binding.scheduleRecycleView.setLayoutManager(new LinearLayoutManager(this));

        adapter = new VisitScheduleAdapter(dataList, type);
        binding.scheduleRecycleView.setAdapter(adapter);
    }

    public void onClick(View view) {
        Intent intent = null;
        int code = 0;
        switch (view.getId()) {
            case R.id.back_btn:
                finish();
                break;
            case R.id.start_time:               //开始时间
                TimePickerDialog startPicker = new TimePickerDialog.Builder()
                        .setType(Type.YEAR_MONTH_DAY_HOURS)
                        .setTitleStringId("开始时间")
                        .setCurrentMillseconds(System.currentTimeMillis())
                        .setThemeColor(getResources().getColor(R.color.yellow))
                        .setWheelItemTextNormalColor(getResources().getColor(R.color.hintColor))
                        .setWheelItemTextSelectorColor(getResources().getColor(R.color.yellow))
                        .setCallBack(this)
                        .build();
                startPicker.show(getSupportFragmentManager(), "year_month_day_hours");
                break;
            case R.id.end_time:                 //结束时间
                TimePickerDialog endPicker = new TimePickerDialog.Builder()
                        .setType(Type.YEAR_MONTH_DAY_HOURS)
                        .setTitleStringId("结束时间")
                        .setCurrentMillseconds(System.currentTimeMillis())
                        .setThemeColor(getResources().getColor(R.color.yellow))
                        .setWheelItemTextNormalColor(getResources().getColor(R.color.hintColor))
                        .setWheelItemTextSelectorColor(getResources().getColor(R.color.yellow))
                        .setCallBack(this)
                        .build();
                endPicker.show(getSupportFragmentManager(), "year_month_day_hours");
                break;
            case R.id.place_to_meet:            //见面地点
                intent = new Intent(VisitScheduleActivity.this, MeetingPlaceActivity.class);
                intent.putExtra("property", getIntent().getStringExtra("property"));
                code = 100;
                break;
            case R.id.delete_icon:              //编辑
                intent = new Intent(this, AddHouseActivity.class);
                intent.putExtra("type", getIntent().getStringExtra("type"));
                //遍历约看房源，获取房源ID
                ArrayList<String> iDList = new ArrayList<>();
                for (Map<String, Object> map : adapter.getData()) {
                    if( map.containsKey("rscode") ) {
                        iDList.add(map.get("rscode").toString());
                    }else if( map.containsKey("rsCode") ) {
                        iDList.add(map.get("rsCode").toString());
                    }
                }
                intent.putExtra("ids", iDList);
                intent.putExtra("oldData", JSON.toJSONString( adapter.getData() ));
                break;
            case R.id.add_visit_house:          //添加带看房源
                //添加房源
                intent = new Intent(this, AddHouseActivity.class);
                intent.putExtra("type", getIntent().getStringExtra("type"));
                break;
            case R.id.preview:                 //预览
                Intent intent1 = new Intent(VisitScheduleActivity.this, PreviewActivity.class);
                if (state.equals("Again")) { //修改预览
                    intent1.putExtra("customerName", getIntent().getStringExtra("customerName"));
                    intent1.putExtra("firsttime", getIntent().getStringExtra("firsttime"));
                    intent1.putExtra("endtime", getIntent().getStringExtra("endtime"));
                    intent1.putExtra("place", place);
                    intent1.putExtra("state", "0");
                    intent1.putExtra("number", getIntent().getIntExtra("number", 0));

                    if (TextUtils.isEmpty(getIntent().getStringExtra("customerName"))) {
                        CustomToast.showToast(this, "请输入客户姓名", 2000);
                    } else if (TextUtils.isEmpty(getIntent().getStringExtra("firsttime"))) {
                        CustomToast.showToast(this, "请输入开始时间", 2000);
                    } else if (TextUtils.isEmpty(place)) {
                        CustomToast.showToast(this, "请选择见面地点", 2000);
                    } else if (TextUtils.isEmpty(getIntent().getStringExtra("endtime"))) {
                        CustomToast.showToast(this, "请输入结束时间", 2000);
                    } else if (!CompareDate(binding.firstTimeText.getText().toString(), binding.lastTimeText.getText().toString())) {
                        CustomToast.showToast(this, "开始时间和结束时间要在同一天,并且开始时间要小于结束时间", 2000);
                    } else {
                        ArrayList<Map<String, Object>> data1 = adapter.getData();
                        EventBus.getDefault().postSticky(data1, "TAG_PREVIEW");
                        startActivity(intent1);
                    }
                } else if (state.equals("Input")) { //添加预览
                    intent1.putExtra("firsttime", startTimeStr);
                    intent1.putExtra("endtime", endTimeStr);
                    intent1.putExtra("place", place);
                    intent1.putExtra("state", "1");
                    intent1.putExtra("customerName", getIntent().getStringExtra("customerName"));
                    intent1.putExtra("number", count);

                    if (TextUtils.isEmpty(getIntent().getStringExtra("customerName"))) {
                        CustomToast.showToast(this, "请输入客户姓名", 2000);
                    } else if (TextUtils.isEmpty(binding.firstTimeText.getText().toString())) {
                        CustomToast.showToast(this, "请输入开始时间", 2000);
                    } else if (TextUtils.isEmpty(place)) {
                        CustomToast.showToast(this, "请选择见面地点", 2000);
                    } else if (TextUtils.isEmpty(binding.lastTimeText.getText().toString())) {
                        CustomToast.showToast(this, "请输入结束时间", 2000);
                    } else if (!CompareDate(binding.firstTimeText.getText().toString(), binding.lastTimeText.getText().toString())) {
                        CustomToast.showToast(this, "开始时间和结束时间要在同一天,并且开始时间要小于结束时间", 2000);
                    } else {
                        ArrayList<Map<String, Object>> data1 = adapter.getData();
                        EventBus.getDefault().postSticky(data1, "TAG_PREVIEW");
                        startActivity(intent1);
                    }
                }
                break;
            case R.id.save:                     //保存
                if (state.equals("Again")) { //修改约看
                    ArrayList<Map<String, Object>> data = adapter.getData();
                    JSONArray jsonArray = new JSONArray();
                    for (int i = 0; i < data.size(); i++) {
                        JSONObject object = new JSONObject();
                        object.put("tags", data.get(i).get("tags"));
                        object.put("houseType", data.get(i).get("houseType"));
                        object.put("recommendReason", data.get(i).get("recommendReason"));
                        object.put("id", data.get(i).get("id"));
                        object.put("rsCode", data.get(i).get("rscode"));
                        jsonArray.add(object);
                    }
                    jsonObject.put("appointmentStartTime", startTimeStr);
                    jsonObject.put("appointmentEndTime", endTimeStr);
                    jsonObject.put("appointmentCode", getIntent().getStringExtra("appointmentCode"));
                    jsonObject.put("address", place);
                    jsonObject.put("pointx", pointx);
                    jsonObject.put("pointy", pointy);
                    jsonObject.put("houseList", jsonArray.toString());

                    if (null == jsonObject.get("address")) {
                        CustomToast.showToast(this, "请选择见面地点", 2000);
                    } else if (null == jsonObject.get("pointx")) {
                        CustomToast.showToast(this, "缺少经度", 2000);
                    } else if (null == jsonObject.get("pointy")) {
                        CustomToast.showToast(this, "缺少纬度", 2000);
                    } else if (null == jsonObject.get("appointmentStartTime")) {
                        CustomToast.showToast(this, "请输入开始时间", 2000);
                    } else if (null == jsonObject.get("appointmentEndTime")) {
                        CustomToast.showToast(this, "请输入结束时间", 2000);
                    } else if (null == jsonObject.get("appointmentCode")) {
                        CustomToast.showToast(this, "缺少约看编码", 2000);
                    } else if (null == jsonObject.get("houseList")) {
                        CustomToast.showToast(this, "缺少约看房源集合", 2000);
                    } else if (!CompareDate(binding.firstTimeText.getText().toString(), binding.lastTimeText.getText().toString())) {
                        CustomToast.showToast(this, "开始时间和结束时间要在同一天,并且开始时间要小于结束时间", 2000);
                    } else {
                        Recompose();
                    }

                } else if (state.equals("Input")) { //录约看
                    ArrayList<Map<String, Object>> data = adapter.getData();
                    JSONArray jsonArray = new JSONArray();
                    for (int i = 0; i < data.size(); i++) {
                        JSONObject object = new JSONObject();
                        object.put("tags", data.get(i).get("tags"));
                        object.put("houseType", data.get(i).get("houseType"));
                        object.put("recommendReason", data.get(i).get("recommendReason"));
                        object.put("rsCode", data.get(i).get("rscode"));
                        jsonArray.add(object);
                    }
                    commitObjcet.put("appointmentStartTime", startTimeStr);
                    commitObjcet.put("appointmentEndTime", endTimeStr);
                    commitObjcet.put("csCode", getIntent().getStringExtra("csCode"));
                    if (getIntent().getStringExtra("type").equals("sale")) {
                        commitObjcet.put("type", 1);//出售
                    } else {
                        commitObjcet.put("type", 0);//出租
                    }
                    commitObjcet.put("customerName", getIntent().getStringExtra("customerName"));
                    commitObjcet.put("address", place);
                    commitObjcet.put("pointx", pointx);
                    commitObjcet.put("pointy", pointy);
                    commitObjcet.put("houseList", jsonArray.toString());

                    if (null == commitObjcet.get("address")) {
                        CustomToast.showToast(this, "请选择见面地点", 2000);
                    } else if (null == commitObjcet.get("pointx")) {
                        CustomToast.showToast(this, "缺少经度", 2000);
                    } else if (null == commitObjcet.get("pointy")) {
                        CustomToast.showToast(this, "缺少纬度", 2000);
                    } else if (TextUtils.isEmpty(binding.firstTimeText.getText().toString())) {
                        CustomToast.showToast(this, "请输入开始时间", 2000);
                    } else if (TextUtils.isEmpty(binding.lastTimeText.getText().toString())) {
                        CustomToast.showToast(this, "请输入结束时间", 2000);
                    } else if (null == commitObjcet.get("csCode")) {
                        CustomToast.showToast(this, "缺少客源编码", 2000);
                    } else if (null == commitObjcet.get("houseList")) {
                        CustomToast.showToast(this, "缺少带看房源集合", 2000);
                    } else if (null == commitObjcet.get("customerName")) {
                        CustomToast.showToast(this, "请输入客户名称", 2000);
                    } else if (null == commitObjcet.get("type")) {
                        CustomToast.showToast(this, "缺少交易类型", 2000);
                    } else if (!CompareDate(binding.firstTimeText.getText().toString(), binding.lastTimeText.getText().toString())) {
                        CustomToast.showToast(this, "开始时间和结束时间要在同一天,并且开始时间要小于结束时间", 2000);
                    } else {
                        CommitForm();
                    }
                }
                break;
            default:
                break;
        }
        if (null != intent) {
            startActivityForResult(intent, code);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 100) {
            if (resultCode == RESULT_OK) {
                binding.addressMeet.setText(data.getStringExtra("address"));
                place = data.getStringExtra("address");
                GetPoint(data.getStringExtra("address"), data.getStringExtra("city"));
            }
        }
    }


    @Override
    public void onDateSet(TimePickerDialog timePickerView, long millseconds) {
        if (timePickerView.getTitle().equals("开始时间")) {
            binding.firstTimeText.setText(DateUtil.getTime(millseconds, "yyyy-MM-dd HH:mm"));
            startTimeStr = DateUtil.getTime(millseconds, "yyyy-MM-dd HH");
        } else if (timePickerView.getTitle().equals("结束时间")) {
            binding.lastTimeText.setText(DateUtil.getTime(millseconds, "yyyy-MM-dd HH:mm"));
            endTimeStr = DateUtil.getTime(millseconds, "yyyy-MM-dd HH");
        }
    }

    @Subscriber(tag = "TAG_FINISH_CHECKED")
    public void data(ArrayList<Map<String, Object>> data) {
        if (data.size() > 0) {
            binding.scheduleRecycleView.setVisibility(View.VISIBLE);
            binding.bottomAddHouse.setVisibility(View.GONE);
            binding.houseCount.setText("约看房源(" + data.size() + ")");
            count = data.size();
            ArrayList<Map<String, Object>> cData = new ArrayList<>();
            for (int i = 0; i < data.size(); i++) {
                Map<String, Object> sMap = data.get(i);
                Map<String, Object> map = new HashMap<>();
                map.put("estate", sMap.get("estate").toString());
                map.put("shsHouseType", sMap.get("houseType").toString());
                map.put("square", String.valueOf(sMap.get("square")));
                map.put("unitPrice", String.valueOf(sMap.get("unitPrice")));
                map.put("county", String.valueOf(sMap.get("county")));
                map.put("area", String.valueOf(sMap.get("area")));
                if( sMap.containsKey("salePrice") )
                map.put("price", String.valueOf(sMap.get("salePrice")));
                if(  sMap.containsKey("rentPrice")  )
                    map.put("price", String.valueOf(sMap.get("rentPrice")));
                map.put("rscode", sMap.get("rscode"));
                map.put("imgUrl", sMap.get("image"));
                map.put("type", getIntent().getStringExtra("type"));

                cData.add(map);
            }
            adapter.setData(cData);
        }
    }

    @Subscriber(tag = "TAG_SELECT_TAG")
    public void select(ArrayList<Map<String, Object>> data) {
        adapter.setData(data);
        adapter.notifyDataSetChanged();
    }

    @Subscriber(tag = "TAG_HOUSE_LIST")
    public void getlist(ArrayList<Map<String, Object>> data) {
        EventBus.getDefault().removeStickyEvent(data.getClass(), "TAG_HOUSE_LIST");
        EventBus.getDefault().postSticky(data, "TAG_DATA");
        adapter.setData(data);
        adapter.notifyDataSetChanged();
    }

    @Override
    protected void onDestroy() {
        if (null != progressDialog && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    /**
     * 修改
     */
    private void Recompose() {
        progressDialog.show();
        OkHttpUtils
                .postString()
                .url(ApiConfig.APPOINTMENT_MODIFICATION)
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .content(jsonObject.toString())
                .build()
                .execute(new MapCallBack() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        if (null != progressDialog && progressDialog.isShowing()) {
                            progressDialog.dismiss();
                        }
                        e.printStackTrace();
                    }

                    @Override
                    public void onResponse(Map<String, Object> response, int id) {
                        if (null != progressDialog && progressDialog.isShowing()) {
                            progressDialog.dismiss();
                        }
                        if (DataFilter.filter(VisitScheduleActivity.this, response, null)) {
                            CustomToast.showToast(VisitScheduleActivity.this, "修改成功", 2000);
                            finish();
                        }
                    }
                });
    }

    /**
     * 提交
     */
    public void CommitForm() {
        progressDialog.show();
        OkHttpUtils
                .postString()
                .url(ApiConfig.APPOINTMENT_COMMIT_FORM)
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .content(commitObjcet.toString())
                .build()
                .execute(new MapCallBack() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        if (null != progressDialog && progressDialog.isShowing()) {
                            progressDialog.dismiss();
                        }
                        e.printStackTrace();
                    }

                    @Override
                    public void onResponse(Map<String, Object> response, int id) {
                        if (null != progressDialog && progressDialog.isShowing()) {
                            progressDialog.dismiss();
                        }
                        if (DataFilter.filter(VisitScheduleActivity.this, response, null)) {
                            CustomToast.showToast(VisitScheduleActivity.this, "提交成功", 2000);
                            finish();
                        }
                    }
                });
    }

    @Subscriber(tag = "TAG_PLACE_NAME")
    public void getplace(Map<String, String> map) {
        this.place = map.get("place");
        this.state = map.get("property");
        binding.addressMeet.setText(place);
        GetPoint(map.get("place"), map.get("city"));
    }

    /**
     * 获取经纬度
     *
     * @param address
     */
    public void GetPoint(String address, String city) {

        //新建编码查询对象
        GeoCoder geocode = GeoCoder.newInstance();
        //新建查询对象要查询的条件
        GeoCodeOption GeoOption = new GeoCodeOption().city(city).address(address);
        //发起地理编码请求
        geocode.geocode(GeoOption);
        //设置查询结果监听者
        geocode.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {
            /**
             * 地理编码查询结果回调函数
             * @param geoCodeResult  地理编码查询结果
             */
            @Override
            public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {
                if( geoCodeResult.getLocation() !=null ) {
                    pointy = String.valueOf(geoCodeResult.getLocation().latitude);
                    pointx = String.valueOf(geoCodeResult.getLocation().longitude);
                }else{
                    CustomToast.showToast(VisitScheduleActivity.this,"地址解析错误，请重选",1500);
                }
            }

            /**
             * 反地理编码查询结果回调函数
             * @param reverseGeoCodeResult  反地理编码查询结果
             */
            @Override
            public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {

            }
        });
    }

    /**
     * 比较日期
     *
     * @return 同一天返回 true
     */
    public boolean CompareDate(String firstTime, String endTime) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH");
        try {
            Date StartTime = sdf.parse(firstTime);
            Date StartTime1 = sdf1.parse(firstTime);
            Date lastTime = sdf.parse(endTime);
            Date lastTime1 = sdf1.parse(endTime);
            if (lastTime.getTime() == StartTime.getTime()) {
                if (StartTime1.getTime() < lastTime1.getTime()) {
                    return true;
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return false;
    }
}

